using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace PrintScreen
{
    public class ActionTodo_Save:ActionToDo
    {
        public ActionTodo_Save(ImageInfo i)
            : base(i)
        {

        }
        public static List<string> Save(string Where, ImageInfo i,ImageFormat ifo)
        {
            if(i == null)
                throw new ArgumentException("must be some image to save!");
            if (ifo == ImageFormat.MemoryBmp)
                throw new ArgumentException("Memory bmp can not be saved!");

            
            if (!Directory.Exists(Where))
                Directory.CreateDirectory(Where);

            List<string> ret = new List<string>(2);
            DateTime dt=DateTime.Now;

            string PathToSave = Path.Combine(Where,dt.ToString("yyyyMMdd"));
            if(!Directory.Exists(PathToSave))
                Directory.CreateDirectory(PathToSave);

            PathToSave = Path.Combine(PathToSave, dt.ToString("hhmmss") + "_" + i.ValidFileName );
            
            ret.Add(PathToSave + "." + ifo.ToString());
            ret.Add(PathToSave + "_active." + ifo.ToString());
            i.Screen.Save(ret[0], ifo);
            i.ActiveWindow.Save(ret[1], ifo);

            return ret;

        }
        public ImageFormat format = ImageFormat.Png;

        private string m_FileNameFull;
        public string FileNameFull
        {
            get
            {

                return m_FileNameFull;
            }

        }
        private string m_FileNameActive;
        public string FileNameActive
        {
            get
            {
                return m_FileNameActive;
            }
        }
        
        public override void DoAction()
        {
            if (string.IsNullOrEmpty(actionData))
            {
                actionData = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                actionData =Path.Combine(actionData,"PrintScreen");
                if (!Directory.Exists(actionData))
                    Directory.CreateDirectory(actionData);
            }
            
            List<string> s=Save(actionData, image,  format);
            m_FileNameFull = s[0];
            m_FileNameActive = s[1];
            
            base.DoAction();
        }
    }
}
